package com.itstudio.portal.controller;

import com.itstudio.portal.entity.RestResponse;
import com.itstudio.portal.entity.dto.NewsAddDto;
import com.itstudio.portal.service.NewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/news")
public class NewsController {

    @Resource
    NewsService newsService;

    //查询全部全部的接口
    @GetMapping("/list")
    public RestResponse list(Integer pageNum, Integer pageSize, @RequestParam(value = "id", required = false) Long id){
        return newsService.getList(pageNum, pageSize, id);
    }

    @GetMapping("/getNews/{id}")
    public RestResponse getNews(@PathVariable Long id){
        return newsService.getNewsById(id);
    }

    //添加新闻接口
    @PostMapping("/addNews")
    public RestResponse addNews(@RequestBody NewsAddDto newsAdd){
        return newsService.addNews(newsAdd);
    }

    //修改新闻接口
    @PutMapping("/updateNews")
    public RestResponse updateNews(@RequestBody NewsAddDto newsAdd){
        return newsService.updateNews(newsAdd);
    }

    //删除新闻接口
    @DeleteMapping("/deleteNews/{id}")
    public RestResponse deleteNews(@PathVariable Long id){
        return newsService.deleteNews(id);
    }

    //增加新闻浏览量接口
    @GetMapping("updateView/{id}")
    public RestResponse updateView(@PathVariable Long id){
        return newsService.updateView(id);
    }

}
